﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WeiTap.Data.Utilities;

namespace WeiTap.Data.Core
{
    public interface IProvider
    {
        /// <summary>
        /// 翻页帮助类
        /// </summary>
        IPagingHelper PagingUtility { get; }
        /// <summary>
        /// 数据库是否支持GUID/UUID
        /// </summary>
        bool HasNativeGuidSupport { get; }
        /// <summary>
        /// 转换成对应的DBProvider数据库的表名称
        /// </summary>
        /// <param name="tableName"></param>
        /// <returns></returns>
        string EscapeTableName(string tableName);
        /// <summary>
        /// 转换成对应的DBProvider数据库的自增列定义
        /// </summary>
        /// <param name="sqlIndentifier"></param>
        /// <returns></returns>
        string EscapeSqlIdentifier(string sqlIndentifier);
        /// <summary>
        /// 转换成对应的DBProvider数据库的翻页SQL语句
        /// </summary>
        /// <param name="skip">起始行号</param>
        /// <param name="take">返回的行数</param>
        /// <param name="parts">SQL拆分后的部件</param>
        /// <param name="args"></param>
        /// <returns></returns>
        string BuildPageQuery(long skip, long take, SQLParts parts, ref object[] args);
        /// <summary>
        /// 转换对应的SQL类型为C#类型
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        object MapParameterValue(object value);
        /// <summary>
        /// 在执行任何SQL语句之前的执行
        /// </summary>
        /// <param name="cmd"></param>
        Task PreExecuteAsync(DbCommand cmd);
        string GetExistsSql();
        /// <summary>
        /// 异步执行一条命令
        /// </summary>
        /// <param name="database"></param>
        /// <param name="cmd"></param>
        /// <param name="primaryKeyName"></param>
        /// <returns></returns>
        Task<object> ExecuteInsertAsync(Database database, DbCommand cmd, string primaryKeyName);
        /// <summary>
        /// 执行一条Insert语句后，获取主键值得表达式
        /// </summary>
        /// <param name="primaryKeyName"></param>
        /// <returns></returns>
        string GetInsertOutputClause(string primaryKeyName);
        /// <summary>
        /// 获取定义参数的前缀字符串
        /// </summary>
        /// <param name="connectionString"></param>
        /// <returns></returns>
        string GetParameterPrefix(string connectionString);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="tableInfo"></param>
        /// <returns></returns>
        string GetAutoIncrementExpression(TableInfo tableInfo);
        DbProviderFactory GetFactory();
    }
}
